home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / e / explorer.lzh / empty-handler.e < prev    next >
Text File  |  1995-12-14  |  3KB  |  104 lines

  1. /***
  2.   Returns the number of X's specified as filename:
  3.   "Copy Empty:100 Ram:test" will create a file "test" in Ram:
  4.   containing 100 X's
  5. ***/
  6.  
  7. OPT OSVERSION=37, PREPROCESS
  8.  
  9. MODULE 'dos/dos',
  10.        'dos/dosextens',
  11.        'dos/filehandler',
  12.        'exec/ports',
  13.        'exec/nodes',
  14.        'rexx/rxslib',
  15.        'rexxsyslib',
  16.        'amigalib/ports',
  17.        '*sendexplorer'
  18.  
  19. ENUM ERR_NONE, ERR_LIB
  20.  
  21. RAISE ERR_LIB IF OpenLibrary()=NIL
  22.  
  23. PROC getpacket (p:PTR TO process)
  24.   DEF port:PTR TO mp, msg:PTR TO mn
  25.   port:=p.msgport    -> The port of our process
  26.   WaitPort(port)     -> Wait for a message
  27.   msg:=GetMsg(port) 
  28. ENDPROC msg.ln.name
  29.  
  30. PROC main() HANDLE
  31.   DEF myrep=NIL:PTR TO mp
  32.   rexxsysbase:=OpenLibrary(RXSNAME, 0)
  33.   IF NIL=(myrep:=createPort(NIL,0)) THEN Raise("PORT")
  34.   handler(myrep)
  35. EXCEPT DO
  36.   IF myrep THEN deletePort(myrep)
  37.   IF rexxsysbase THEN CloseLibrary(rexxsysbase)
  38. ENDPROC
  39.  
  40. PROC initialpacket(myrep)
  41.   DEF proc:PTR TO process, packet:PTR TO dospacket, ln:PTR TO ln,
  42.       dev:PTR TO devicenode
  43.   proc:=FindTask(NIL)
  44.   ln:=wbmessage
  45.   packet:=ln.name
  46.   wbmessage:=NIL
  47.   dev:=BADDR(packet.arg3)
  48.   dev.task:=proc.msgport
  49.   sendExplorer(packet, 'dospacket', myrep)
  50.   ReplyPkt(packet, DOSTRUE, 0)
  51. ENDPROC proc, dev
  52.  
  53. PROC handler(myrep)
  54.   DEF proc, packet:PTR TO dospacket, dev:PTR TO devicenode,
  55.       fh:PTR TO filehandle, running=TRUE, opencount=0,
  56.       readlen, c, s, filename[64]:STRING, type
  57.   proc,dev:=initialpacket(myrep)
  58.   WHILE running
  59.     packet:=getpacket(proc)
  60.     sendExplorer(packet, 'dospacket', myrep)
  61.     type:=packet.type
  62.     SELECT type
  63.     CASE ACTION_FINDINPUT
  64.       s:=BADDR(packet.arg3)
  65.       c:=0
  66.       WHILE c<s[]
  67.         filename[c]:=s[c+1]
  68.         INC c
  69.       ENDWHILE
  70.       filename[c]:=0
  71.       s:=filename
  72.       WHILE s[] AND (s[]<>":") DO INC s
  73.       IF s[]=":" THEN INC s
  74.       c:=Val(s)
  75.       INC opencount
  76.       fh:=BADDR(packet.arg1)
  77.       fh.interactive:=0         -> Non-interactive file
  78.       fh.args:=fh
  79.       fh.arg2:=c
  80.       ReplyPkt(packet, DOSTRUE, 0)
  81.     CASE ACTION_READ
  82.       fh:=packet.arg1
  83.       s:=packet.arg2
  84.       readlen:=Min(fh.arg2, packet.arg3)
  85.       c:=0
  86.       WHILE c<readlen
  87.         s[]++:="X"
  88.         INC c
  89.       ENDWHILE
  90.       fh.arg2:=fh.arg2-readlen
  91.       ReplyPkt(packet, readlen, 0)
  92.     CASE ACTION_WRITE
  93.       ReplyPkt(packet, DOSFALSE, ERROR_DISK_WRITE_PROTECTED)
  94.     CASE ACTION_END
  95.       DEC opencount
  96.       running:=opencount<>0
  97.       ReplyPkt(packet, DOSTRUE, 0)
  98.     DEFAULT
  99.       ReplyPkt(packet, DOSFALSE, ERROR_ACTION_NOT_KNOWN)
  100.     ENDSELECT
  101.   ENDWHILE
  102.   dev.task:=FALSE
  103. ENDPROC
  104.